package cn.agiledata.bank.transaction.action;

import java.lang.reflect.InvocationTargetException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.agiledata.bank.account.facade.AccountFacade;
import cn.agiledata.bank.account.service.AccountSummary;
import cn.agiledata.bank.account.service.IAccountConst;
import cn.agiledata.bank.account.service.IAccountService;
import cn.agiledata.bank.audit.service.AuditService;
import cn.agiledata.bank.common.dao.AccountTemplateInter;
import cn.agiledata.bank.common.service.ICommonService;
import cn.agiledata.bank.common.service.PermissionService;
import cn.agiledata.bank.common.servlet.InitForString;
import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.common.util.DateUtil;
import cn.agiledata.bank.common.util.ForeDict;
import cn.agiledata.bank.common.util.IOUtil;
import cn.agiledata.bank.common.util.PageBean;
import cn.agiledata.bank.common.util.SecurityUtil;
import cn.agiledata.bank.common.util.StringUtil;
import cn.agiledata.bank.common.util.WeatherUtil;
import cn.agiledata.bank.hibernateBean.Account;
import cn.agiledata.bank.hibernateBean.ActionType;
import cn.agiledata.bank.hibernateBean.AuditOperandType;
import cn.agiledata.bank.hibernateBean.AuditOperation;
import cn.agiledata.bank.hibernateBean.EsPrePayTrans;
import cn.agiledata.bank.hibernateBean.Groups;
import cn.agiledata.bank.hibernateBean.HistoryAuditOperation;
import cn.agiledata.bank.hibernateBean.Operator;
import cn.agiledata.bank.hibernateBean.SubAccount;
import cn.agiledata.bank.myspace.service.IMySpaceService;
import cn.agiledata.bank.netReturn.logic.NetReturnResponse;
import cn.agiledata.bank.transaction.audit.service.EsPrePayTransService;
import cn.agiledata.bank.transaction.dao.EsPrePayTransPageList;
import cn.agiledata.bank.transaction.exception.TransactionException;
import cn.agiledata.bank.transaction.form.EsAuditHistory;
import cn.agiledata.bank.transaction.form.EsPrePayTransForm;
import cn.agiledata.bank.transaction.logic.BatchTransSummary;
import cn.agiledata.bank.transaction.logic.EsPrePayTransBean;
import cn.agiledata.bank.transaction.logic.TransDetail;
import cn.agiledata.bank.transaction.service.EsPrePayTransFactory;
import cn.agiledata.bank.transaction.service.FeeRatioInterf;
import cn.agiledata.bank.transaction.service.GetEsPrePayTrans;
import cn.agiledata.bank.transaction.service.GetEsPrePayTransImpl;
import cn.agiledata.bank.transaction.service.TransactionService;

import com.vnv.infrastructure.action.IPBBaseAction;
import com.vnv.infrastructure.exception.IPBException;
import com.vnv.infrastructure.logic.IPBAppFactory;
import com.vnv.infrastructure.logic.IPBMgrFactory;
import com.vnv.infrastructure.util.PagingResult;

public class EsTransAction extends IPBBaseAction {

    private EsPrePayTransService getEsPrePayTransService() throws IPBException {
        return (EsPrePayTransService) IPBAppFactory
                .getObj(ForeDict.SERVICE_ES_PRE_PAY_TRANS);
    }

    protected IMySpaceService getMySpaceService() {
        return (IMySpaceService) IPBAppFactory
                .getObj(ForeDict.SERVICE_MY_SPACE);
    }

    private AuditService getAuditService() {
        return (AuditService) IPBAppFactory.getObj(ForeDict.SERVICE_AUDIT);
    }

    private AccountTemplateInter getAccountTemplate() {
        return (AccountTemplateInter) IPBMgrFactory
                .getMgr(ForeDict.ACCOUNT_TEMPLATE);
    }

    private ICommonService getCommonService() {
        return (ICommonService) IPBAppFactory.getObj(ForeDict.SERVICE_COMMON);
    }

    private IAccountService getAccountService() {
        return (IAccountService) IPBAppFactory.getObj(ForeDict.SERVICE_ACCOUNT);
    }

    private FeeRatioInterf getFeeRatioInterf() {
        return (FeeRatioInterf) IPBMgrFactory
                .getMgr(ForeDict.SERVICE_FEE_RATIO);
    }

    private AccountFacade getAccountFacade() {
        return (AccountFacade) IPBAppFactory.getObj(ForeDict.FACADE_ACCOUNT);
    }

    protected final TransactionService getTransactionService() {
        return (TransactionService) IPBAppFactory
                .getObj(ForeDict.SERVICE_TRANSACTION);
    }
    
    /**
     * 在进入查询待审核、待支付、审核失败交易列表时调用，重置session中的Form
     */
    private void resetEsPrePayTransForm(HttpServletRequest request,
            EsPrePayTransForm form) {
        form.resetExceptTransStatus();
        boolean batchType = Boolean.valueOf(request.getParameter("batchType"))
                .booleanValue();
        form.setBatchType(batchType);
    }

    public ActionForward waitingAuditList(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        EsPrePayTransForm form = (EsPrePayTransForm) actionForm;
        resetEsPrePayTransForm(request, form);
        form.setTransStatus(Constant.ES_TRANS_STATUS_UNAUDIT);
        return toWaitPay(mapping, actionForm, request, response);
    }

    public ActionForward waitingAuditQuery(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        EsPrePayTransForm form = (EsPrePayTransForm) actionForm;

        form.setTransStatus(Constant.ES_TRANS_STATUS_UNAUDIT);
        return toWaitPay(mapping, actionForm, request, response);
    }

    public ActionForward waitingPayList(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        EsPrePayTransForm form = (EsPrePayTransForm) actionForm;
        resetEsPrePayTransForm(request, form);
        form.setTransStatus(Constant.ES_TRANS_STATUS_UNPAY);
        return toWaitPay(mapping, actionForm, request, response);
    }

    public ActionForward auditRejectList(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        EsPrePayTransForm form = (EsPrePayTransForm) actionForm;
        resetEsPrePayTransForm(request, form);
        form.setTransStatus(Constant.ES_TRANS_STATUS_REJECTED);
        return toWaitPay(mapping, actionForm, request, response);
    }

    public ActionForward auditRejectQuery(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        EsPrePayTransForm form = (EsPrePayTransForm) actionForm;
        form.setTransStatus(Constant.ES_TRANS_STATUS_REJECTED);
        return toWaitPay(mapping, actionForm, request, response);
    }

    /**
     * 临时交易列表(审核，支付，提交3种列表)
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward toWaitPay(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        EsPrePayTransForm form = (EsPrePayTransForm) actionForm;
        
        PermissionService pif = PermissionService.getPermissionService();
        // 获得Account对象
        Account account = getAccountFacade().currentAccount(request);
        String accountId = account.getId().toString();
        SubAccount defaultSA = account.getDefaultSubAccount();
        String transStatus = form.getTransStatus();
        if (request.getAttribute("batchType") != null && "true".equals(request.getAttribute("batchType").toString()))
            form.setBatchType(true);
        EsPrePayTransBean bean = new EsPrePayTransBean();
        bean.setAccount(account);
        List subList = new ArrayList();
        if (pif.isCorpOperator(request)) {
            if (Constant.ES_TRANS_STATUS_UNAUDIT.equals(transStatus)) {
                subList = this.getCommonService().getSubAccountList(accountId);
            } else if (Constant.ES_TRANS_STATUS_UNPAY.equals(transStatus)) {
                if (Constant.ACTION_TYPE_D.equals(form.getActionTypeID())
                        || Constant.ACTION_TYPE_G
                                .equals(form.getActionTypeID())) {
                    subList = pif.getSubAccounts(request,
                            Constant.PERMIS_TYPE_GAINMONEY, defaultSA);
                } else {
                    subList = pif.getSubAccounts(request,
                            Constant.PERMIS_TYPE_PAYMONEY, defaultSA);
                }
            } else if (Constant.ES_TRANS_STATUS_REJECTED.equals(transStatus)) {
                subList = this.getCommonService().getSubAccountList(accountId);
                bean.setCreateUser(WeatherUtil.getOperator(request).getId()
                        .toString());

            } else { // 不合法的交易状态
                throw TransactionException.INVALID_QUERY_PARAMETER;
            }
        }
        bean.setSubAccounts(subList);
        request.setAttribute("subList", subList);
        if (StringUtil.isStrEmpty(form.getStartPage())) {
            bean.setStartPage("1");
        } else {
            bean.setStartPage(form.getStartPage());
        }

        bean.setTransStatus(transStatus);
        if (WeatherUtil.getOperator(request) != null) {
            bean.setOperatorSeq(WeatherUtil.getOperator(request).getId()
                    .toString());
        } else {
            bean.setOperatorSeq("-1");// 当登陆的为admin的时候，因为他没有操作员，所以在这里set一个-1，这样他就查不到任何数据了
        }
        setBean(request, form, bean);
        // 选择全部交易类型时使用
        String batchModel = (String) request.getSession().getAttribute("batchModel");
		if ("1".equals(batchModel))form.setBatchType(true);
		request.getSession().removeAttribute("batchModel");
		
        bean.setActionTypes(getActionTypeIds(form.isBatchType(), account));
        PageBean waitList;
        ActionForward forward;
        if (form.isBatchType()) { // 批量
            EsPrePayTransService esPrePayTransService = getEsPrePayTransService();
            if (Constant.ES_TRANS_STATUS_UNPAY.equals(transStatus)) { // 批量待支付
                waitList = esPrePayTransService.getBatchTransSummaryList(bean);
                forward = mapping.findForward("batchWaitingPay");
            } else if (Constant.ES_TRANS_STATUS_UNAUDIT.equals(transStatus)
                    && StringUtil.isStrEmpty(request
                            .getParameter("batchNumber"))) {
                waitList = esPrePayTransService
                        .getBatchAuditingTransSummaryList(bean);
                getEsPrePayTransService().setSummary(waitList.getData(),
                        WeatherUtil.getOperator(request));
                forward = mapping.findForward("batch");
            } else if (Constant.ES_TRANS_STATUS_REJECTED.equals(transStatus)
                    && StringUtil.isStrEmpty(request
                            .getParameter("batchNumber"))) {
                bean.setUpdateUserId(WeatherUtil.getOperator(request).getId());

                waitList = esPrePayTransService
                        .getBatchAuditeRejectTransSummaryList(bean);
                getEsPrePayTransService().setSummary(waitList.getData(),
                        WeatherUtil.getOperator(request));
                forward = mapping.findForward("batch");
            } else {
                // BatchTransSummary[] batchNoList = esPrePayTransService
                // .getBatchTransSummaryListOnlyBatchNo(account,
                // transStatus);
                // request.setAttribute("batchNoList", batchNoList);
                // if (StringUtil.isStrEmpty(bean.getBatchNo())
                // && batchNoList.length > 0) {
                // bean.setBatchNo((String) batchNoList[0].getBatchNo());
                // }
                bean.setBatchNo(request.getParameter("batchNumber"));
                bean.setAmountMax(null);
                bean.setAmountMin(null);
                bean.setBeginDate(null);
                bean.setEndDate(null);
                loadBatchTransSummary(request, bean.getBatchNo());

                waitList = new EsPrePayTransPageList(bean)
                        .getAccountListPageBean();
                if (Constant.ES_TRANS_STATUS_UNAUDIT.equals(transStatus))
                    request.setAttribute("ifBatchAudit", esPrePayTransService
                            .ifAllAudited(bean.getBatchNo(), WeatherUtil
                                    .getOperator(request))
                            + "");
                if (Constant.ES_TRANS_STATUS_REJECTED.equals(transStatus))
                    request.setAttribute("requiredBatchManage",
                            requiredManage(request.getParameter("batchNumber"))
                                    + "");

                forward = mapping.findForward("batch");
            }
        } else { // 单笔
        	if(IAccountConst.COMPANY_TYPE_GATEWAY.equals(account.getCompanyType())) {
            	bean.setActionTypeID(Constant.ACTION_TYPE_R);
            }
            waitList = new EsPrePayTransPageList(bean).getAccountListPageBean();
            forward = mapping.findForward("single");
        }
        resetPageBean(waitList, WeatherUtil.getOperator(request));
        request.setAttribute("waitPayList", waitList);
        request.setAttribute("actionTypeList", getActionTypeList(form
                .isBatchType(), account));
        if (!StringUtil.isStrEmpty(transStatus))
            request.setAttribute("transStatus", transStatus);
        else
            request.setAttribute("transStatus", "");// 输入一个0，当这个为0的时候，前台页面显示所有tranStatus的数据
        request.setAttribute("batchType", Boolean.valueOf(form.isBatchType()));
        form.setActionType(null);
        form.setSubAccountID("");
        return forward;
    }

    private void resetPageBean(PageBean waitList, Operator oper)
            throws IllegalAccessException, InvocationTargetException,
            IPBException {
        List list = waitList.getData();
        List newList = new ArrayList();
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Object object = it.next();
            if (!(object instanceof EsPrePayTrans)) { // 查询结果记录不为EsPrePayTrans时不需要转换
                return;
            }
            EsPrePayTrans trans = (EsPrePayTrans) object;
            TransDetail detail = new TransDetail();
            BeanUtils.copyProperties(detail, trans);
            newList.add(detail);
            if (getAuditService().hasAuditAuthority(
                    getEsPrePayTransService().getAuditOperandType(
                            detail.getActionType().getId().toString()),
                    trans.getId().longValue(), oper)) {
                detail.setAudit("true");
            } else {
                detail.setAudit("false");
            }
        }
        waitList.setData(newList);
    }

    /**
     * 零时交易详细页面显示(审核，支付)
     * 
     * @param mapping
     * @param actionForm
     * @param request
     * @param response
     * @return
     * @throws IPBException
     * @throws Exception
     */
    public ActionForward esPerPayTransPayDetail(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws IPBException, Exception {

        // 获得交易对象
        String tid = "";
        tid = request.getParameter("transactionID");
        if ("".equals(tid)) {
            tid = "0";
        }
        EsPrePayTrans aqb = getEsPrePayTransService().getEsPrePayTransById(
                (new Long(tid)).longValue());
        request.setAttribute("aqb", aqb);

        long accountId = WeatherUtil.getAccountIdFromSession(request);

        request.setAttribute("bankInfo", InitForString.dataDictMap
                .get("BANK_INFO"));

        // 获得当前操作员
        AccountSummary accountsummary = WeatherUtil
                .getLoingInfoFromSession(request);
        Operator operator = null;
        if (accountsummary.getOperatorCode() != null) {
            operator = accountsummary.getOperatorByIdInstance(String
                    .valueOf(accountsummary.getOperatorCode()));
        }

        String type = request.getParameter("type");
        request.setAttribute("type", type);

        EsPrePayTrans esTran = getEsPrePayTransService()
                .getEsPrePayTransByTransId(aqb.getTransId());

        String actionType = String.valueOf(esTran.getActionType().getId());
        AuditOperandType auditOperandType = getEsPrePayTransService()
                .getAuditOperandType(actionType);
        HistoryAuditOperation[] haos = getAuditService()
                .getHistoryAuditOperations(auditOperandType,
                        esTran.getId().longValue());
        List history = new ArrayList();
        for (int i = 0; i < haos.length; i++) {
            EsAuditHistory his = new EsAuditHistory(haos[i]);
            Operator o = (getMySpaceService().getOperatorById(haos[i]
                    .getUpdateUser()));
            if (o == null) {
                Account account = getMySpaceService().getAccount(
                        haos[i].getUpdateUser());
                his.setUpdateUserName(account.getName());
            } else {
                his.setUpdateUserName(o.getOperatorName());
            }
            history.add(his);
        }
        request.setAttribute("history", history);

        // 获得Account对象
        Account account = this.getAccountTemplate().getAccount(
                String.valueOf(accountId));
        // 获得费率的Groups对象
        Groups group = getMySpaceService().getGroupByAccount(account,
                Constant.GROUP_TYPE_A);

//        // 获得该交易的手续费
//        double debitFee = this.getFeeRatioInterf().getDebitFee(aqb.getDebit(),
//                aqb.getActionType().getId().toString(), aqb.getAmount(),
//                group.getId().toString());
        request.setAttribute("fee", new Double(0.1d));

        if (!"".equals(type)) {

            if (aqb.getTransStatus().equals(Constant.ES_TRANS_STATUS_UNAUDIT)) {// 待审核

                if (type != null) {// 如果是查看，则不需要有审核权限
                    // 待审核交易处理
                    if (operator == null
                            || !getAuditService().hasAuditAuthority(
                                    auditOperandType, aqb.getId().longValue(),
                                    operator)) {
                        request.setAttribute("Error",
                                Constant.ES_TRANS_STATUS_UNAUDIT);
                    }

                }
                
                // 交易类型不是账户间交易（单笔是提现或付款至他人银行账户，批量是付款至他人银行账户）
                if (!Constant.ACTION_TYPE_C.equals(aqb.getActionType().getId().toString()) && !Constant.ACTION_TYPE_Y.equals(aqb.getActionType().getId().toString())) {
                	String bankName0 = getCommonService().getBankInfo(aqb.getBankSeq().toString()).getBankName();
                	request.setAttribute("bankName0", bankName0);
                }
                
                // 如果交易类型不是提现，判断是否具有向个人支付的权限
                if (!Constant.ACTION_TYPE_D.equals(aqb.getActionType().getId().toString())) {
                	try {
                    	getTransactionService().validateTransactable(
                                aqb.getDebit().getAccount(), aqb.getCredit().getAccount(),
                                aqb.getPersonName(), actionType);
                    } catch (TransactionException e) {
                    	request.setAttribute("b2c_notavaiable", getAppExceptionMessage(request, e));
                    }
                }

            } else if (aqb.getTransStatus().equals(
                    Constant.ES_TRANS_STATUS_UNPAY)) {// 待支付
                // 待支付交易处理
            	// 交易类型不是账户间交易（单笔是提现或付款至他人银行账户，批量是付款至他人银行账户）
                if (!Constant.ACTION_TYPE_C.equals(aqb.getActionType().getId().toString())) {
                	String bankName0 = "";
                	if(aqb.getBankCitySeq() != null) {
	                	bankName0 = getCommonService().getBankInfo(
								aqb.getBankSeq().toString()).getBankName();
                	}
                	request.setAttribute("bankName0", bankName0);
                }
                
                // 如果交易类型不是提现，判断是否具有向个人支付的权限
                if (!Constant.ACTION_TYPE_D.equals(aqb.getActionType().getId().toString())) {
                	try {
                    	getTransactionService().validateTransactable(
                                aqb.getDebit().getAccount(), aqb.getCredit().getAccount(),
                                aqb.getPersonName(), actionType);
                    } catch (TransactionException e) {
                    	request.setAttribute("b2c_notavaiable", getAppExceptionMessage(request, e));
                    }
                }
            	
            } else if (aqb.getTransStatus().equals(
                    Constant.ES_TRANS_STATUS_REJECTED)) {// 审核失败（待重审）

                // 组合EsPrePayTransForm
                EsPrePayTransForm form = (EsPrePayTransForm) actionForm;

                BeanUtils.copyProperties(form, aqb);

                form.setCreditId(aqb.getCredit().getId().toString());
                form.setDebitId(aqb.getDebit().getId().toString());
                if (StringUtil.isStrEmpty(aqb.getCredit().getAccount()
                        .getEmail())) {
                    form.setCreditMsg(aqb.getCredit().getAccount().getMobile());
                } else {
                    form.setCreditMsg(aqb.getCredit().getAccount().getEmail());
                }

                // 获得该交易类型的收费模式
                request.setAttribute("feeRatio", this.getFeeRatioInterf()
                        .getFeeRatio(group,
                                aqb.getActionType().getId().toString()));

                // 子账户列表
                PermissionService pif = PermissionService
                        .getPermissionService();
                if (!pif.isCorpOperator(request)) {
                    // 个人用户或企业用户admin
                    request.setAttribute("subAccounts", this.getCommonService()
                            .getSubAccountList(String.valueOf(accountId)));
                } else {
                    // 企业用户操作员
                    SubAccount defaultSA = account.getDefaultSubAccount();
                    request
                            .setAttribute("subAccounts", pif.getSubAccounts(
                                    request, Constant.PERMIS_TYPE_GAINMONEY,
                                    defaultSA));
                }
                // 子账户银行卡列表
                List banklist = this.getAccountService().getBankBySubaccountId(
                        WeatherUtil.getSubAccountIdFromSession(request));
                request.setAttribute("BankList", banklist);

                request.setAttribute("displayBean", this.getCommonService()
                        .getDisplayName(String.valueOf(accountId)));

                if (Constant.ACTION_TYPE_C.equals(aqb.getActionType().getId()
                        .toString())) {// 该交易类型为账户间交易
                    request.setAttribute("tradeType", WeatherUtil
                            .getTradeType());
                    
                    // 判断是否具有向个人支付的权限
                    try {
                    	getTransactionService().validateTransactable(
                    			aqb.getDebit().getAccount(), aqb.getCredit().getAccount(),
                    			aqb.getPersonName(), actionType);
                    } catch (TransactionException e) {
                    	request.setAttribute("b2c_notavaiable", getAppExceptionMessage(request, e));
                    }
                    
                    return mapping.findForward("vnvTran");
                }
                if (Constant.ACTION_TYPE_D.equals(aqb.getActionType().getId()
                        .toString())) {// 该交易类型为提现

                    return mapping.findForward("gainMoney");
                }
                if (Constant.ACTION_TYPE_G.equals(aqb.getActionType().getId()
                        .toString())) {// 该交易类型为付款至他人银行账户（原来叫账户付款给对方银行？，由账户直付生成的交易）
                    request.setAttribute("BankList", InitForString.dataDictMap
                            .get("ENTERPRISE_BANK_INFO"));

                    // 省份列表
                    List provinceList = (List) InitForString.dataDictMap
                            .get("PROVINCE_INFO");
                    request.setAttribute("province", provinceList);

                    request.setAttribute("transactionId", aqb.getId());
                    
                    // 判断是否具有向个人支付的权限
                    try {
                    	getTransactionService().validateTransactable(
                    			aqb.getDebit().getAccount(), aqb.getCredit().getAccount(),
                    			aqb.getPersonName(), actionType);
                    } catch (TransactionException e) {
                    	request.setAttribute("b2c_notavaiable", getAppExceptionMessage(request, e));
                    }

                    return mapping.findForward("payDir");
                }
                if (Constant.ACTION_TYPE_R.equals(aqb.getActionType().getId()
                        .toString())) {
                	String bankName0 = getCommonService().getBankInfo(aqb.getBankSeq().toString()).getBankName();
                	request.setAttribute("bankName0", bankName0);
                }
                
            }
        }

        return mapping.findForward("esPerPayTransPayDetail");
    }

    /**
     * 审核操作action
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IPBException
     * @throws Exception
     */
    public ActionForward esPerPayTransPayAudit(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws IPBException, Exception {

        String tid = "";
        tid = request.getParameter("transactionID");
        if ("".equals(tid)) {
            tid = "0";
        }
        String audit = "";
        audit = request.getParameter("audit");
        if ("".equals(audit)) {
            audit = "Y";
        }

        EsPrePayTransService esPrePayTransService = getEsPrePayTransService();
        // 获得交易对象
        EsPrePayTrans aqb = esPrePayTransService
                .getEsPrePayTransById((new Long(tid)).longValue());
        request.setAttribute("aqb", aqb);

        // 获得当前操作员
        AccountSummary accountsummary = WeatherUtil
                .getLoingInfoFromSession(request);
        Operator operator = null;
        if (accountsummary.getOperatorCode() != null) {
            operator = accountsummary.getOperatorByIdInstance(String
                    .valueOf(accountsummary.getOperatorCode()));
        }
        String actionType = String.valueOf(aqb.getActionType().getId());
        AuditOperandType auditOperandType = esPrePayTransService
                .getAuditOperandType(actionType);
        String auditReason = request.getParameter("attitude");
        // 判断同意还是拒绝
        if ("Y".equals(audit)) {
            // 同意
            getAuditService().agree(auditOperandType, aqb.getId().longValue(),
                    operator, auditReason);
            if (getAuditService().isFinished(auditOperandType,
                    aqb.getId().longValue())) {
                aqb.setTransStatus(Constant.ES_TRANS_STATUS_UNPAY);
                esPrePayTransService.saveOrUpdate(aqb);
            }

        } else {
            // 拒绝
            getAuditService().reject(auditOperandType, aqb.getId().longValue(),
                    operator, auditReason);
            aqb.setTransStatus(Constant.ES_TRANS_STATUS_REJECTED);
            esPrePayTransService.saveOrUpdate(aqb);
        }
        boolean ifPay = getMySpaceService().ifCouldPay(
                accountsummary.getOperatorCode().toString(),
                aqb.getDebit().getId().toString());
        ifPay = ifPay
                && getAuditService().isFinished(auditOperandType,
                        aqb.getId().longValue());
        String batchNo = aqb.getBatchNo();
        if (!StringUtil.isStrEmpty(batchNo)) {
            ifPay = ifPay
                    && esPrePayTransService
                            .batchEsPrePayTransCanBePaid(batchNo);
            request.setAttribute("batchType", Boolean.TRUE);
            EsPrePayTransForm esForm = new EsPrePayTransForm();
            esForm.setTransStatus(Constant.ES_TRANS_STATUS_UNAUDIT);
            esForm.setBatchType(true);
            esForm.setActionTypeID(aqb.getActionType().getId().toString());
            return toWaitPay(mapping, esForm, request, response);
            // return mapping.findForward("go");
        }
        if (ifPay)
            return mapping.findForward("ifPay");
        else {
            return mapping.findForward("go");
        }
    }

    /**
     * 批量审核
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IPBException
     * @throws Exception
     */
    public ActionForward batchAudit(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws IPBException, Exception {

        String audit = "";
        audit = request.getParameter("audit");
        if ("".equals(audit)) {
            audit = "Y";
        }
        String batchNo = request.getParameter("viewBatchNo");
        EsPrePayTransService esPrePayTransService = getEsPrePayTransService();

        List aqbs = esPrePayTransService.getEsPrePayTranses(batchNo);
        Iterator it = aqbs.iterator();
        while (it.hasNext()) {
            // 获得交易对象
            EsPrePayTrans aqb = (EsPrePayTrans) it.next();
            if (Constant.ES_TRANS_STATUS_CANCEL.equals(aqb.getTransStatus()))
                continue;
            // request.setAttribute("aqb", aqb);

            // 获得当前操作员
            AccountSummary accountsummary = WeatherUtil
                    .getLoingInfoFromSession(request);
            Operator operator = null;
            if (accountsummary.getOperatorCode() != null) {
                operator = accountsummary.getOperatorByIdInstance(String
                        .valueOf(accountsummary.getOperatorCode()));
            }

            String actionType = String.valueOf(aqb.getActionType().getId());
            AuditOperandType auditOperandType = esPrePayTransService
                    .getAuditOperandType(actionType);
            String auditReason = request.getParameter("attitude");
            // 判断同意还是拒绝
            if ("Y".equals(audit)) {
                // 同意
                getAuditService().agree(auditOperandType,
                        aqb.getId().longValue(), operator, auditReason);
                if (getAuditService().isFinished(auditOperandType,
                        aqb.getId().longValue())) {
                    aqb.setTransStatus(Constant.ES_TRANS_STATUS_UNPAY);
                    esPrePayTransService.saveOrUpdate(aqb);

                }

            } else {
                // 拒绝
                getAuditService().reject(auditOperandType,
                        aqb.getId().longValue(), operator, auditReason);
                aqb.setTransStatus(Constant.ES_TRANS_STATUS_REJECTED);
                esPrePayTransService.saveOrUpdate(aqb);
            }
        }

        return mapping.findForward("go");
    }
    
    /**
     * 批量取消（待支付的批量交易）
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IPBException
     * @throws Exception
     */
    public ActionForward batchCancel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws IPBException, Exception {
    	String batchNo = request.getParameter("batchNo");
    	
    	EsPrePayTransService esPrePayTransService = getEsPrePayTransService();
    	List list = esPrePayTransService.getEsPrePayTranses(batchNo);
        Iterator it = list.iterator();
        while (it.hasNext()) {
        	// 获得交易对象
            EsPrePayTrans aqb = (EsPrePayTrans) it.next();
            
            //取消本批中所有待支付的交易
            if (Constant.ES_TRANS_STATUS_UNPAY.equals(aqb.getTransStatus())) {
            	esPrePayTransService.deleteEsPrePayTrans(aqb.getId().longValue());
            }
        }
    	
        ActionForward forward = mapping.findForward("go");
        String backUrl = request.getContextPath() + forward.getPath();
        if (backUrl.indexOf("?") >= 0) {
            backUrl += "&";
        } else {
            backUrl += "?";
        }
        backUrl += "batchType=true";
        request.setAttribute("back", backUrl);
        
        return mapping.findForward(FORWARD_GLOBAL_SUCCESS);
    }

    /**
     * 支付操作action
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IPBException
     * @throws Exception
     */
    public ActionForward esPerPayTransPayToPay(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws IPBException, Exception {
        String tid = "";
        tid = request.getParameter("id");
        if ("".equals(tid)) {
            tid = "0";
        }

        // 获得交易对象
        EsPrePayTrans aqb = getEsPrePayTransService().getEsPrePayTransById(
                (new Long(tid)).longValue());
        request.setAttribute("aqb", aqb);

        String actionType = aqb.getActionType().getId().toString();

        // 判断当前用户是否具有付款权限
        String permitType = "";
        
        PermissionService permissionService = PermissionService
                .getPermissionService();
        if (Constant.ACTION_TYPE_D.equals(actionType)) {
        	permitType = Constant.PERMIS_TYPE_GAINMONEY;
        } else if (Constant.ACTION_TYPE_R.equals(actionType)) {
        	permitType = Constant.PERMIS_TYPE_RETURN;
        } else {
        	permitType = Constant.PERMIS_TYPE_PAYMONEY;
        }
//        permitType = Constant.ACTION_TYPE_D.equals(actionType) ? Constant.PERMIS_TYPE_GAINMONEY
//                : Constant.PERMIS_TYPE_PAYMONEY;
        if (!permissionService.hasPermission(request, permitType)) {
            String message = getAppExceptionMessage(request,
                    TransactionException.NO_PERMISSION);
            request.setAttribute("message", message);
            return mapping.findForward("error");
        }

        // 判断子帐户余额是否足够支付这笔钱
        if (!getEsPrePayTransService().enoughDebitBalance(aqb)) {
            String message = "您的子帐户余额不够，请查询您的余额";
            request.setAttribute("message", message);
            return mapping.findForward("error");
        }

        // 判断是否具有交易权限
        getTransactionService().validateTransactable(
                aqb.getDebit().getAccount(), aqb.getCredit().getAccount(),
                aqb.getPersonName(), actionType);

        AccountSummary as = (AccountSummary) request.getSession().getAttribute(
                Constant.SESSION_ACCOUNT_SUMMARY);
        Operator operator = as.getOperatorByIdInstance(String.valueOf(as
                .getOperatorCode()));

        // 检验支付密码
        String pinkUpPass = request.getParameter("pinkUpPass");
        if (!SecurityUtil.encryptoMD5String(pinkUpPass).equals(
                operator.getPayPassword())) {
            request.setAttribute("Error", "4");
            return mapping.findForward("error");
        }

        // 根据不同的actionType调用不用的保存方法
        GetEsPrePayTrans getEsPrePayTran = new GetEsPrePayTransImpl();
        String transStatus = aqb.getTransStatus();
        EsPrePayTransFactory epptf = getEsPrePayTran.getTransaction(String
                .valueOf(aqb.getActionType().getId()));
        epptf.esPrePayTransToTransaction(aqb);
        ActionForward forward = Constant.ES_TRANS_STATUS_UNPAY
                .equals(transStatus) ? mapping.findForward("go2") : mapping
                .findForward("go");
        String backUrl = request.getContextPath() + forward.getPath();
        request.setAttribute("back", backUrl);
        
//      商户通过接口退款时,退款成功后台通知:
        NetReturnResponse netReturn = (NetReturnResponse)request.getSession().getAttribute("netReturnResponse");
        if (netReturn != null 
        		&& (netReturn.getBatchNo().equals(aqb.getOrderId())||netReturn.getBatchNo().equals(aqb.getTransId()))){
        	Map parameters = new HashMap();
        	parameters.put("merchantId", netReturn.getAccountId());
        	parameters.put("orderNo", netReturn.getOrderId());
        	parameters.put("amount", netReturn.getAmount());
        	parameters.put("returnCode", netReturn.getSuccess());
        	parameters.put("mac", netReturn.getMac());
        	try {
				IOUtil.postNetReturnUrl(netReturn.getMerchantUrl(), parameters);
			} catch (RuntimeException e) {
				e.printStackTrace();
			}
        	request.getSession().removeAttribute("netReturnResponse");
        }
        
        return mapping.findForward(FORWARD_GLOBAL_SUCCESS);
    }

    /**
     * 保存esPerPayTransPay对象
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IPBException
     * @throws Exception
     */
    public ActionForward esPerPayTransPayUpdate(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws IPBException, Exception {
        EsPrePayTransService service = getEsPrePayTransService();
        EsPrePayTransForm eppt = (EsPrePayTransForm) form;
        EsPrePayTrans tran = service.updateByType(eppt, request);
        Operator operator = WeatherUtil.getOperator(request);
        service.submitAuditOperation(tran, operator);
        if (request.getParameter("batchNumber") != null) {
            EsPrePayTransForm esForm = new EsPrePayTransForm();
            esForm.setTransStatus(Constant.ES_TRANS_STATUS_REJECTED);
            esForm.setBatchType(true);
            esForm.setActionTypeID(eppt.getActionTypeID());
            return toWaitPay(mapping, esForm, request, response);
        } else {
            return mapping.findForward("success");
        }

    }

    /**
     * 保存esPerPayTransPay对象 但是status不变
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IPBException
     * @throws Exception
     */
    public ActionForward esPerPayTransPayUpdateWithoutStatus(
            ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws IPBException, Exception {
        EsPrePayTransService service = getEsPrePayTransService();
        EsPrePayTransForm eppt = (EsPrePayTransForm) form;
        service.updateByTypeWithoutStatus(eppt, request);
        if (request.getParameter("batchNumber") != null) {
            EsPrePayTransForm esForm = new EsPrePayTransForm();
            esForm.setTransStatus(Constant.ES_TRANS_STATUS_REJECTED);
            esForm.setBatchType(true);
            return toWaitPay(mapping, esForm, request, response);
        } else {
            return mapping.findForward("success");
        }
    }

    /**
     * 逻辑删除esPerPayTransPay对象
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IPBException
     * @throws Exception
     */
    public ActionForward esPerPayTransPayDel(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws IPBException, Exception {
        EsPrePayTransService service = getEsPrePayTransService();
        String id = request.getParameter("transactionID");
        service.deleteEsPrePayTrans(new Long(id).longValue());
        
        String oldStatus = request.getParameter("oldStatus");
        ActionForward forward = null;
        if (oldStatus.equals(Constant.ES_TRANS_STATUS_UNPAY)) {
        	forward = mapping.findForward("accessWaitingPayList");
        } else {
        	forward = mapping.findForward("accessAuditRegectList");
        }
        
        String backUrl = request.getContextPath() + forward.getPath();
        boolean batchType = Boolean.valueOf(request.getParameter("batchType"))
                .booleanValue();
        if (backUrl.indexOf("?") >= 0) {
            backUrl += "&";
        } else {
            backUrl += "?";
        }
        backUrl += "batchType=" + batchType;
        request.setAttribute("back", backUrl);
        
        return mapping.findForward(FORWARD_GLOBAL_SUCCESS);
    }

    public ActionForward auditHis(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws IPBException, Exception {
        String id = request.getParameter("transactionID");
        EsPrePayTrans aqb = getEsPrePayTransService().getEsPrePayTransById(
                (new Long(id)).longValue());
        String actionType = String.valueOf(aqb.getActionType().getId());
        AuditOperandType auditOperandType = getEsPrePayTransService()
                .getAuditOperandType(actionType);
        HistoryAuditOperation[] ho = getAuditService()
                .getHistoryAuditOperations(auditOperandType,
                        new Long(id).longValue());
        List history = new ArrayList();
        for (int i = 0; i < ho.length; i++) {
            AuditOperation type = ho[i];
            EsAuditHistory his = new EsAuditHistory(type);
            his.setUpdateUserName((getMySpaceService().getOperatorById(type
                    .getUpdateUser())).getOperatorName());
            history.add(his);
        }
        request.setAttribute("history", history);
        return mapping.findForward("access");
    }

    private void setBean(HttpServletRequest request, EsPrePayTransForm form,
            EsPrePayTransBean bean) {
        bean.setBatchType(form.isBatchType());
        bean.setBatchNo(form.getBatchNo());
        bean.setTransId(form.getTransId());
        if (!StringUtil.isStrEmpty(form.getStrBeginDate()))
            bean.setBeginDate(DateUtil.string2Date(form.getStrBeginDate()));
        if (!StringUtil.isStrEmpty(form.getStrEndDate()))
            bean.setEndDate(DateUtil.string2Date(form.getStrEndDate()));
        bean.setAmountMax(form.getAmountMax());
        bean.setAmountMin(form.getAmountMin());
        if (!StringUtil.isStrEmpty(form.getActionTypeID())) {
            bean.setActionTypeID(form.getActionTypeID());
        } else {
        	// zln 修正 2008-1-12 修改页面可以选择全部交易类型，不知此处为何限制类型，暂时屏蔽
//            bean.setActionTypeID("3");
        }

        bean.setSubAccountID(form.getSubAccountID());
        bean.setBeginCount(form.getBeginCount());
        bean.setEndCount(form.getEndCount());
    }

    private List getActionTypeList(boolean batch, Account account) {
        List list = new ArrayList();
        IMySpaceService mySpaceService = getMySpaceService();
        list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_C));
        if (!batch)
            list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_D));
        list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_G));
        // zln 修正 20080225
        list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_R));
        list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_Y));
        return list;
    }
    
    /**
     * 取得相应的ActionTypeId列表
     * 
     * @param batch
     * @return
     */
    private List getActionTypeIds(boolean batch, Account account) {
    	List list = new ArrayList();
        IMySpaceService mySpaceService = getMySpaceService();
        list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_C).getId());
        if (!batch)
            list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_D).getId());
        list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_G).getId());
        // zln 修正 20080225
        list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_R).getId());
        
        list.add(mySpaceService.getActionTypeById(Constant.ACTION_TYPE_Y).getId());
        return list;
    }

    public ActionForward viewEsBatchTransPeerAccount(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        EsPrePayTransForm form = (EsPrePayTransForm) actionForm;
        String batchNo = form.getBatchNo();
        int pageNo = form.getPageNo();
        if (pageNo <= 0) {
            pageNo = 1;
        }
        int pageSize = form.getPageSize();
        if (pageSize <= 0) {
            pageSize = 10; // 默认每页10条记录
        }
        PagingResult pb = getEsPrePayTransService()
                .getEsPrePayTransListByBatchNo(batchNo, pageNo, pageSize);
        request.setAttribute("result", pb);
        // 此处结果记录条数必然大于0
        ActionType actionType = pb.getRecordCount() == 0 ? null
                : ((EsPrePayTrans) pb.getRecords().get(0)).getActionType();
        request.setAttribute("actionType", actionType);
        return mapping.findForward(FORWARD_SUCCESS);
    }

    public ActionForward esBatchPayTransSummary(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Boolean toPay = Boolean.valueOf(request.getParameter("toPay"));
        request.setAttribute("toPay", toPay);
        String batchNo = request.getParameter("viewBatchNo");
        loadBatchTransSummary(request, batchNo);
        return mapping.findForward(FORWARD_SUCCESS);
    }

    private void loadBatchTransSummary(HttpServletRequest request,
            String batchNo) throws IPBException {
        EsPrePayTransService epptSrevice = getEsPrePayTransService();
        BatchTransSummary totalSummary = epptSrevice
                .getBatchTransSummaryTotal(batchNo);
        request.setAttribute("totalSummary", totalSummary);
        BatchTransSummary[] btss = epptSrevice
                .getBatchTransSummaryListGroupByTransStatus(batchNo);
        for (int i = 0; i < btss.length; i++) {
            if (Constant.ES_TRANS_STATUS_CANCEL
                    .equals(btss[i].getTransStatus())) {
                request.setAttribute("cancelSummary", btss[i]);
            } else if (Constant.ES_TRANS_STATUS_REJECTED.equals(btss[i]
                    .getTransStatus())) {
                request.setAttribute("rejectedSummary", btss[i]);
            } else if (Constant.ES_TRANS_STATUS_UNAUDIT.equals(btss[i]
                    .getTransStatus())) {
                request.setAttribute("unauditSummary", btss[i]);
            } else if (Constant.ES_TRANS_STATUS_UNPAY.equals(btss[i]
                    .getTransStatus())) {
                request.setAttribute("unpaySummary", btss[i]);
            }
        }
    }

    private boolean requiredManage(String batchNo) throws IPBException {
        EsPrePayTransService epptSrevice = getEsPrePayTransService();
        BatchTransSummary totalSummary = epptSrevice
                .getBatchTransSummaryTotal(batchNo);
        BatchTransSummary[] btss = epptSrevice
                .getBatchTransSummaryListGroupByTransStatus(batchNo);
        BatchTransSummary cancelSummary = null;
        BatchTransSummary rejectSummary = null;
        long cancel = 0;
        long reject = 0;
        for (int i = 0; i < btss.length; i++) {
            if (Constant.ES_TRANS_STATUS_CANCEL
                    .equals(btss[i].getTransStatus())) {
                cancelSummary = btss[i];
                if (cancelSummary != null)
                    cancel = cancelSummary.getStatusCount();
            } else if (Constant.ES_TRANS_STATUS_REJECTED.equals(btss[i]
                    .getTransStatus())) {
                rejectSummary = btss[i];
                if (rejectSummary != null)
                    reject = rejectSummary.getStatusCount();
            }
        }
        return (cancel + reject) == totalSummary.getTotalCount();
    }

    public ActionForward esBatchPayTransToPay(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
    	String batchNo = request.getParameter("viewBatchNo");
    	String actionTypeID = request.getParameter("actionTypeID");
        try {
            String password = request.getParameter("password");
            if (!getAccountFacade().isCorrectPayPassword(request, password)) {
                throw TransactionException.PAY_PASSWORD_ERROR;
            }
            

            // 判断当前用户是否具有付款权限
            String permitType = "";
            
            PermissionService permissionService = PermissionService
                    .getPermissionService();
            if (Constant.ACTION_TYPE_D.equals(actionTypeID)) {
            	permitType = Constant.PERMIS_TYPE_GAINMONEY;
            } else if (Constant.ACTION_TYPE_R.equals(actionTypeID)) {
            	permitType = Constant.PERMIS_TYPE_RETURN;
            } else {
            	permitType = Constant.PERMIS_TYPE_PAYMONEY;
            }
            if (!permissionService.hasPermission(request, permitType)) {
            	throw TransactionException.NO_PERMISSION;
            }
            
            String subAccountID = request.getParameter("subAccountID");
            if (Constant.ACTION_TYPE_Y.equals(actionTypeID)){
            	List esPrePayTransList = getEsPrePayTransService().getEsPrePayTransListByBatchNo(batchNo);
            	Account account = getAccountFacade().currentAccount(request);
            	SubAccount subAccount = getAccountFacade().getSubAccountById(Long.parseLong(subAccountID));
            	for (int i = 0; i < esPrePayTransList.size(); i++) {
                    EsPrePayTrans esPrePayTrans = (EsPrePayTrans) esPrePayTransList
                            .get(i);
                    String transStatus = esPrePayTrans.getTransStatus();
                    // 只有待支付交易才进行最终支付
                    if (Constant.ES_TRANS_STATUS_UNPAY.equals(transStatus)) {
                    }
            	}
            } 
        } catch (TransactionException e) {
            // 处理业务逻辑异常
            handleAppException(mapping, actionForm, request, response, e);
            // 跳转到支付页面
            esBatchPayTransSummary(mapping, actionForm, request, response);
            return mapping.findForward(FORWARD_FAILURE);
        }
        ActionForward successForward = mapping.findForward(FORWARD_SUCCESS);
        String backUrl = request.getContextPath() + successForward.getPath();
        request.setAttribute("back", backUrl);
        //商户通过接口退款时,退款成功后台通知:
        NetReturnResponse netReturn = (NetReturnResponse)request.getSession().getAttribute("netReturnResponse");
        if (netReturn != null && netReturn.getBatchNo().equals(batchNo)){
        	Map parameters = new HashMap();
        	parameters.put("merchantId", netReturn.getAccountId());
        	parameters.put("orderNo", netReturn.getOrderId());
        	parameters.put("amount", netReturn.getAmount());
        	parameters.put("returnCode", netReturn.getSuccess());
        	parameters.put("mac", netReturn.getMac());
        	try {
				IOUtil.postNetReturnUrl(netReturn.getMerchantUrl(), parameters);
			} catch (RuntimeException e) {
				e.printStackTrace();
			}
        	request.getSession().removeAttribute("netReturnResponse");
        }
        return mapping.findForward(FORWARD_GLOBAL_SUCCESS);

    }

    public ActionForward batchAuditRejectManage(ActionMapping mapping,
            ActionForm actionForm, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        String batchNo = request.getParameter("viewBatchNo");
        EsPrePayTransService esPrePayTransService = getEsPrePayTransService();
        List aqbs = esPrePayTransService.getEsPrePayTranses(batchNo);
        Iterator it = aqbs.iterator();
        Operator operator = WeatherUtil.getOperator(request);
        while (it.hasNext()) {
            EsPrePayTrans aqb = (EsPrePayTrans) it.next();
            if (Constant.ES_TRANS_STATUS_REJECTED.equals(aqb.getTransStatus())) {
                getEsPrePayTransService().updateStatus(aqb, request);
                getEsPrePayTransService().submitAuditOperation(aqb, operator);
            }
        }

        return mapping.findForward("success");
    }
    
    private void doDirect(String urls) {
    	URL url = null;
        HttpURLConnection httpurlconnection = null;
        try
        {
          url = new URL(urls);

          httpurlconnection = (HttpURLConnection) url.openConnection();
          httpurlconnection.setDoOutput(true);
          httpurlconnection.setRequestMethod("POST");
          httpurlconnection.getOutputStream().flush();
          httpurlconnection.getOutputStream().close();
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
        finally
        {
          if(httpurlconnection!=null)
            httpurlconnection.disconnect();
        }
    }
}

